var CrmWebFormList=function(t){this.init=function(t){this.context=BX(t.context);this.canEdit=t.canEdit;this.nodeHead=this.context.querySelector(".intranet-button-list-header");this.headHideClass="crm-webform-title-close";this.formAttribute="data-bx-crm-webform-item";this.formAttributeIsSystem="data-bx-crm-webform-item-is-system";this.forms=[];this.mess=t.mess||{};var e=this.context.querySelectorAll("["+this.formAttribute+"]");for(var i=0;i<e.length;i++){var o=e.item(i);var s=o.getAttribute(this.formAttribute);var n=o.getAttribute(this.formAttributeIsSystem)=="Y";this.initForm({caller:this,id:s,node:o,isSystem:n,detailPageUrlTemplate:t.detailPageUrlTemplate,actionRequestUrl:t.actionRequestUrl,remoteData:!!t.remoteData[s]?t.remoteData[s]:{},localData:!!t.localData[s]?t.localData[s]:{}})}};this.onBeforeDeleteForm=function(t){var e=this.forms.filter(function(t){return t.isSystem==false});if(e.length>1){return}BX.addClass(this.nodeHead,this.headHideClass)};this.onAfterDeleteForm=function(t){var e=BX.util.array_search(t,this.forms);if(e>-1){delete this.forms[e]}};this.onRevertDeleteForm=function(t){BX.removeClass(this.nodeHead,this.headHideClass)};this.initForm=function(t){var e=new CrmWebFormListItem(t);this.forms.push(e)};this.init(t)};function CrmWebFormListItem(t){this.caller=t.caller;this.id=t.id;this.node=t.node;this.isSystem=t.isSystem;this.actionRequestUrl=t.actionRequestUrl;this.detailPageUrlTemplate=t.detailPageUrlTemplate;this.remoteData=t.remoteData;this.localData=t.localData;this.nodeDelete=this.node.querySelector(".copy-to-buffer-button");this.nodeCopyToClipboard=this.node.querySelector(".copy-to-clipboard-node");this.nodeCopyToClipboardButton=this.node.querySelector(".copy-to-clipboard-button");this.nodeSiteList=this.node.querySelector(".intranet-button-list-site-restriction-list");this.nodeSiteListSaved=this.node.querySelector(".intranet-button-list-site-restriction-saved");this.siteListSavedTimeout=null;this.nodeDelete=this.node.querySelector("[data-bx-crm-webform-item-delete]");this.nodeSettings=this.node.querySelector("[data-bx-crm-webform-item-settings]");this.nodeViewSettings=this.node.querySelector("[data-bx-crm-webform-item-view-settings]");this.nodeView=this.node.querySelector("[data-bx-crm-webform-item-view]");this.isActiveControlLocked=false;this.popupSettings=null;this.popupViewSettings=null;this.activeController=new CrmWebFormListItemActiveDateController({caller:this});this.bindControls(t)}CrmWebFormListItem.prototype={showErrorPopup:function(t){t=t||{};var e=t.text||this.caller.mess.errorAction;var i=BX.PopupWindowManager.create("crm_webform_list_error",null,{autoHide:true,lightShadow:true,closeByEsc:true,overlay:{backgroundColor:"black",opacity:500}});i.setButtons([new BX.PopupWindowButton({text:this.caller.mess.dlgBtnClose,events:{click:function(){this.popupWindow.close()}}})]);i.setContent('<span class="crm-webform-edit-warning-popup-alert">'+e+"</span>");i.show()},showConfirmPopup:function(t){t=t||{};var e=t.text||this.caller.mess.confirmAction;var i=BX.PopupWindowManager.create("crm_webform_list_confirm",null,{autoHide:true,lightShadow:true,closeByEsc:true,overlay:{backgroundColor:"black",opacity:500}});i.setButtons([new BX.PopupWindowButton({text:this.caller.mess.dlgBtnApply,className:"popup-window-button-accept",events:{click:function(){this.popupWindow.close();t.action.apply(this,[])}}}),new BX.PopupWindowButton({text:this.caller.mess.dlgBtnCancel,events:{click:function(){this.popupWindow.close()}}})]);i.setContent('<span class="crm-webform-edit-warning-popup-confirm">'+e+"</span>");i.show()},changeActive:function(t,e){if(!this.caller.canEdit)return;e=e||false;if(this.isActiveControlLocked)return;var i=this.activeController.isActive(),o=i?"deactivate":"activate",s={};if(o=="activate"){s={REMOTE_DATA:this.remoteData,LOCAL_DATA:this.localData}}else{s={BUTTON_ID:this.id}}if(i)this.activeController.deactivate();else this.activeController.activate();if(e)return;this.isActiveControlLocked=true;this.sendActionRequest(o,s,function(t){this.isActiveControlLocked=false;if(o=="activate"){if(!!t.LOCAL_DATA)this.localData=t.LOCAL_DATA}else if(o=="deactivate"){this.localData={}}},function(t){t=t||{error:true,text:""};this.isActiveControlLocked=false;this.activeController.revert();this.showErrorPopup(t)})},saveSiteRestrictions:function(t){var e=this.getSelectedSites();var i=this;if(e.length===0){return false}var o="saveSiteRestrictions";var s={BUTTON_ID:this.id,SITE_ID:e};clearTimeout(this.siteListSavedTimeout);this.nodeSiteListSaved.classList.remove("active");this.sendActionRequest(o,s,function(t){this.nodeSiteListSaved.classList.add("active");this.siteListSavedTimeout=setTimeout(function(){i.nodeSiteListSaved.classList.remove("active")},3e3)},function(t){t=t||{error:true,text:""};this.showErrorPopup(t)})},preventDeselectLastSite:function(t){var e=this.getSelectedSites();if(e.length===0){t.target.selected=true;return false}},getSelectedSites:function(){var t=[];if(this.nodeSiteList.options){for(var e=0;e<this.nodeSiteList.options.length;e++){opt=this.nodeSiteList.options[e];if(opt.selected){t.push(opt.value||opt.text)}}}return t},redirectToDetailPage:function(t){window.location=this.detailPageUrlTemplate.replace("#id#",t).replace("#form_id#",t)},resetCounters:function(){this.sendActionRequest("reset_counters",{},function(){window.location.reload()})},copy:function(){this.sendActionRequest("copy",{},function(t){this.redirectToDetailPage(t.copiedId)})},delete:function(){this.showConfirmPopup({text:this.caller.mess.deleteConfirmation,action:BX.proxy(function(){var t="crm-webform-row-close";BX.addClass(this.node,t);this.caller.onBeforeDeleteForm(this);this.sendActionRequest("delete",{},function(t){this.caller.onAfterDeleteForm(this)},function(e){BX.removeClass(this.node,t);this.caller.onRevertDeleteForm(this);this.showErrorPopup(e)})},this)})},sendActionRequest:function(t,e,i,o){i=i||null;o=o||BX.proxy(this.showErrorPopup,this);BX.ajax({url:this.actionRequestUrl,method:"POST",data:{action:t,data:e,sessid:BX.bitrix_sessid()},timeout:30,dataType:"json",processData:true,onsuccess:BX.proxy(function(t){t=t||{};if(t.error){o.apply(this,[t])}else if(i){i.apply(this,[t])}},this),onfailure:BX.proxy(function(){var t={error:true,text:""};o.apply(this,[t])},this)})},bindControls:function(){BX.clipboard.bindCopyClick(this.nodeCopyToClipboardButton,{text:this.nodeCopyToClipboard});BX.bind(this.nodeDelete,"click",BX.proxy(this.delete,this));BX.bind(this.activeController.nodeActiveControl,"click",BX.proxy(this.changeActive,this));BX.bind(this.nodeSettings,"click",BX.proxy(this.showSettings,this));BX.bind(this.nodeViewSettings,"click",BX.proxy(this.showViewSettings,this));BX.bind(this.nodeSiteList,"change",BX.proxy(this.saveSiteRestrictions,this));this.nodeSiteList.querySelectorAll("option").forEach(BX.proxy(function(t){BX.bind(t,"click",BX.proxy(this.preventDeselectLastSite,this))},this))},changeClass:function(t,e,i){i=i||false;if(!t){return}if(i){BX.addClass(t,e)}else{BX.removeClass(t,e)}},styleDisplay:function(t,e,i){e=e||false;i=i||"";if(!t){return}t.style.display=e?i:"none"},createPopup:function(t,e,i,o){o=o||{};return BX.PopupMenu.create(t,e,i,{autoHide:true,offsetLeft:o.offsetLeft?o.offsetLeft:-21,offsetTop:o.offsetTop?o.offsetTop:-3,angle:{position:"top",offset:42},events:{onPopupClose:BX.delegate(this.onPopupClose,this)}})},closePopup:function(t){if(t&&t.popupWindow){t.popupWindow.close()}},onPopupClose:function(){}};function CrmWebFormListItemActiveDateController(t){this.caller=t.caller;this.nodeActiveControl=this.caller.node.querySelector("[data-bx-crm-webform-item-active]");this.nodeDate=this.caller.node.querySelector("[data-bx-crm-webform-item-active-date]");this.nodeDateNowActivated=this.caller.node.querySelector("[data-bx-crm-webform-item-active-date-now-a]");this.nodeDateNowDeActivated=this.caller.node.querySelector("[data-bx-crm-webform-item-active-date-now-d]");this.classDateNow="user-container-show-now";this.classDateNowState="user-container-show-now-deact";this.classOn="intranet-button-list-on";this.classOff="intranet-button-list-off";this.isNowShowedCounter=0;this.isRevert=false}CrmWebFormListItemActiveDateController.prototype={isActive:function(){return BX.hasClass(this.nodeActiveControl,this.classOn)},revert:function(){this.isRevert=true;this.toggle();if(this.isNowShowedCounter<2){this.isNowShowedCounter=0}this.isRevert=false},toggle:function(){if(this.isActive()){this.deactivate()}else{this.activate()}},activate:function(){BX.addClass(this.nodeActiveControl,this.classOn);BX.removeClass(this.nodeActiveControl,this.classOff);this.actualizeDate()},deactivate:function(){BX.removeClass(this.nodeActiveControl,this.classOn);BX.addClass(this.nodeActiveControl,this.classOff);this.actualizeDate()},actualizeDate:function(){this.caller.changeClass(this.nodeDate,this.classDateNowState,!this.isActive());this.nodeDate.style.display="";var t=!this.isRevert||this.isNowShowedCounter>1;this.caller.changeClass(this.nodeDate,this.classDateNow,t);this.isNowShowedCounter++}};
//# sourceMappingURL=script.map.js